<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/16/14
 * Time: 11:18 PM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
if(isset($_SESSION["users_id"]) && $_SESSION["group_id"]==1){
    $link_id = $_GET["link_id"];
    settype($link_id, "int");
    $link = LinkDetail($link_id);
    $row_link = mysql_fetch_array($link);
    if (isset($_POST["btnEdit"])) {
        $Title=$_POST["Title"];
        $Linked=$_POST["Linked"];
        $language_id=$_POST["language"];settype($language_id,"int");
        $AnHien=$_POST["AnHien"];settype($AnHien,"int");
        EditLink($link_id,$Title,$Linked,$language_id,$AnHien);
        header("location:index.php?p=linklist");
    }
?>
<form id="maincp" name="form1" method="post" action="">
    <h1 class="h1">Add a link</h1>
    <p>Please complete all form below to add a new link.</p>
    <ul class="list2">
        <li><h3>Title</h3></li>
        <li><input class="input" type="text" name="Title" id="Title" value="<?php echo $row_link['title']; ?>" /></li>
        <li><h3>Link</h3></li>
        <li><input class="input" type="text" name="Linked" id="Linked" value="<?php echo $row_link['linked']; ?>" /></li>
        <li>
            <fieldset>
                <legend><h3>Options</h3></legend>
                <p>Show or Hide this article on your page.</p>
                <label><input <?php if($row_link['hide/show']==0){ echo 'checked="checked"'; } ?> type="radio" name="AnHien" value="0" id="AnHien_0" />Hide</label>
                <label><input <?php if($row_link['hide/show']==1){ echo 'checked="checked"'; } ?>  type="radio" name="AnHien" value="1" id="AnHien_1" />Show</label>
            </fieldset>
        </li>
        <li>
            <fieldset>
                <legend><h3>Language</h3></legend>
                <p>Choose contents language.</p>
                <select name="language" style="width: 100px">
                    <?php
                    $language=LanguageList();
                    while($row_language=mysql_fetch_array($language)){ ?>
                        <?php if($row_link['language_id']==$row_language['language_id']){ ?>
                            <option selected="selected" value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                        <?php }else{ ?>
                            <option value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                        <?php } ?>
                    <?php } ?>
                </select>
            </fieldset>
        </li>
        <li><input class="button addlink" type="submit" name="btnEdit" id="btnEdit" value="Edit Link" /></li>
    </ul>
    <a href="index.php?p=cpanel" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
</form>
<?php
}else{
    header("location:index.php?p=logincp");
}
?>